<?php 
/****

	If you want the best of the world,
give the world your best anytime！
            				——不二
                							
****/

defined('ACCESS')||exit('Forbidden!');

class CommentAction extends Action {
	protected $com;
	protected $art;

	public function __construct(){
		parent::__construct();
		$this->com = new CommentModel();
		$this->art = new ArticleModel();
	}

	//取出所有评论
	public function lists(){
		$arts = $this->art->select();
		foreach ($arts as $key => $value) {
			$where = 'art_id = '.$value['art_id'];
			$arts[$key]['coms'] = $this->com->select($where);
		}
		$this->assign('data',$arts);
		$this->display('com_list.html');
	}

	//删除评论
	public function del(){
		$id = $this->I('id');
		$data = $this->com->find($id);
		if(!$data){
			$this->failure('评论不存在','index.php?group=Admin&module=Comment&action=lists');
		}
		$res = $this->com->delete($id);
		if(!$res){
			$this->failure('删除失败','index.php?group=Admin&module=Comment&action=lists');
		}else{
			//该篇文章下的评论数-1
			$arts = $this->art->find($data['art_id']);
			$arts['num'] -=1;
			$this->art->update($arts);
			header('Location:index.php?group=Admin&module=Comment&action=lists');
		}
	}
}

?>